#!/usr/bin/env python
# coding=utf-8

from aliyunsdkcore.client import AcsClient
from aliyunsdkcore.request import CommonRequest

client = AcsClient('LTAI4G7dYwUbgico4AyyvuD1', 'F2h219sK4jaT87G6FedSbbq3PmEsFs', 'cn-hangzhou')


def send_note(phone, code):
    request = CommonRequest()
    request.set_accept_format('json')
    request.set_domain('dysmsapi.aliyuncs.com')
    request.set_method('POST')
    request.set_protocol_type('https')  # https | http
    request.set_version('2017-05-25')
    request.set_action_name('SendSms')

    request.add_query_param('RegionId', "cn-hangzhou")
    request.add_query_param('PhoneNumbers', phone)
    request.add_query_param('SignName', "新经咨询")
    request.add_query_param('TemplateCode', "SMS_204276783")
    request.add_query_param('TemplateParam', "{\"code\":\"%s\"}" % code)

    response = client.do_action(request)
    # python2:  print(response)
    print(str(response, encoding='utf-8'))

    print(response)
    print(type(response))
    print(dict(str(response)))

if __name__ == '__main__':
    send_note("13232773661","5252")
